<?php

namespace app\models\marketing;

use Yii;

/**
 * This is the model class for table "marketing_basic".
 *
 * @property int $id
 * @property float $sign_in_score 签名积分
 * @property float $refill_min_amount 充值最低金额
 * @property float $refill_return_ticket_ratio 充值送购物券多少, 比例
 * @property float $refill_return_platform_ticket_ratio 充值送多少平台券, 比例
 * @property float $refill_return_score_ratio 充值送积分, 比例
 * @property int|null $refill_return_score_month 积分送几个月
 */
class MarketingBasic extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'marketing_basic';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['sign_in_score', 'refill_min_amount', 'refill_return_ticket_ratio', 'refill_return_platform_ticket_ratio', 'refill_return_score_ratio'], 'number'],
            [['refill_return_score_month'], 'integer'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'sign_in_score' => 'Sign In Score',
            'refill_min_amount' => 'Refill Min Amount',
            'refill_return_ticket_ratio' => 'Refill Return Ticket Ratio',
            'refill_return_platform_ticket_ratio' => 'Refill Return Platform Ticket Ratio',
            'refill_return_score_ratio' => 'Refill Return Score Ratio',
            'refill_return_score_month' => 'Refill Return Score Month',
        ];
    }

    public static function getLastOne()
    {
        $model = self::find()
            ->orderBy(['id' => SORT_DESC])
            ->one();

        if (!$model) {
            $model = new self();
        }

        return $model;
    }

    public static function saveData($data)
    {
        $model = self::getLastOne();

        if ($model->load(['MarketingBasic' => $data]) && $model->save()) {
            return true;
        }
    }
}
